import numpy as np

from FluidClass.FluidSettings import FluidSettings
from ResistanceClass.ResistanceAbstractClass import ResistanceAbstractClass as RAC
from math import log10
from Utilities.MathFunctions import polynom


class StraightRectSmoothWallPipe(RAC):

    def __init__(self,
                 fluid: FluidSettings,
                 length: float,
                 width: float,
                 height: float) -> None:
        super().__init__(fluid, length)
        self.width = width
        self.height = height
        self.type_name = 'Прямой участок'
        self.section = 'Прямоугольное'

    def area(self) -> float:
        return self.width * self.height

    def perimeter(self) -> float:
        return 2 * self.width + 2 * self.height

    def diameter_hydraulic(self) -> float:
        return round(4 * self.area() / self.perimeter(), 4)

    def local_resistance_coefficient(self) -> float:
        return 0

    def resistance_coefficient_lambda(self) -> (str, float):

        if self.reynolds_number() < 2000:
            return 64 / self.reynolds_number()

        elif 2000 <= self.reynolds_number() <= 4000:
            re_database = [2, 2.5, 3, 4]
            lambda_database = [0.032, 0.034, 0.04, 0.04]
            re_database = np.array(re_database) * 10 ** 3
            return polynom(self.reynolds_number(), re_database, lambda_database, 4)

        elif self.reynolds_number() > 4000:
            return 1 / ((1.8 * log10(self.reynolds_number()) - 1.64) ** 2)

    def get_params_geom(self):
        self.params_geom['Длина'] = str(self.length) + ' м'
        self.params_geom['Ширина'] = str(self.width) + ' м'
        self.params_geom['Высота'] = str(self.height) + ' м'
        return self.params_geom

